
<?php
//模块插件类
//对外接口函数类，其他插件可通过“$this->plugin('jy_bankcard')->方法名” 来调用本类的方法
defined('BY_JYA') or exit('error');
class func_jy_bankcard extends plugin{
	public function bankcard($host,$path){
		$setting=$this->plugin_setting('setting');
		$host = $host;  //你的域名
		$path =$path;       //路径
		$method = "POST";
		$appcode = $setting['appcode']; //你自己的AppCode
		$headers = array();
		array_push($headers, "Authorization:APPCODE " . $appcode);
		//根据API的要求，定义相对应的Content-Type
		array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
		$querys = "";
		//$bodys = "{\"inputs\":[{\"image\":{\"dataType\":50,#50表示image的数据类型为字符串\"dataValue\":\"base64_image_string\"#图片以base64编码的string}}]}";
		$url = $host . $path;
		if($fp = fopen($url, "rb", 0)) { 
        $binary = fread($fp, filesize($url)); // 文件读取
        fclose($fp); 
        $base64 = base64_encode($binary); // 转码
    }
		$request = array();
		$request["image"] = array(
				"dataType" => 50,
				"dataValue" => $base64
		);
		$body = json_encode(array("inputs" => array($request)));
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
		curl_setopt($curl, CURLOPT_URL, $url);
		curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
		curl_setopt($curl, CURLOPT_FAILONERROR, false);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_HEADER, true);
		if (1 == strpos("$".$host, "https://"))
		{
			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
			curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
		}
		curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
		return (curl_exec($curl));

}
?>
